package com.jiyoukeji.template.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.jiyoukeji.template.pojo.User;
import com.jiyoukeji.template.service.UserService;
import com.jiyoukeji.template.utils.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * @Author: 李培洋
     * @Date: 2024/11/20 23:25
     * @Description: （测试）获取用户表数据
     */
    @GetMapping("/user")
    public List<User> getUser(String id) {
        return userService.find(id);
    }

    /**
     * @Author: 李培洋
     * @Date: 2024/11/20 23:25
     * @Description: 用户登录
     */
    @PostMapping("/login")
    public Result<String> userLogin(String id) {
        StpUtil.login(10001);

        SaTokenInfo tokenInfo = StpUtil.getTokenInfo();

        System.out.println(tokenInfo);
        return Result.success("登录成功", tokenInfo.getTokenValue());
    }
}
